package com.stock;

import com.kevin.entity.StockDetail;

import java.util.Map;

public class StockDetailParser implements Parser{
	
/**
 {
     "SZ002657": {
         "symbol": "SZ002657",
         "exchange": "SZ",
         "code": "002657",
         "name": "中科金财",
         "current": "84.12",
         "percentage": "-5.53",
         "change": "-4.92",
         "open": "89.05",
         "high": "89.6",
         "low": "83.65",
         "close": "0.0",
         "last_close": "89.04",
         "high52week": "186.0",
         "low52week": "45.03",
         "volume": "1.2911334E7",
         "volumeAverage": "15745216",
         "marketCapital": "2.667062164228E10",
         "eps": "0.34",
         "pe_ttm": "184.1279",
         "pe_lyr": "343.2384",
         "beta": "0.0",
         "totalShares": "316979102",
         "time": "Wed Dec 23 14:22:19 +0800 2015",
         "afterHours": "0.0",
         "afterHoursPct": "0.0",
         "afterHoursChg": "0.0",
         "updateAt": "1450785613985",
         "dividend": "0.06",
         "yield": "0.03",
         "turnover_rate": "6.69",
         "instOwn": "0.0",
         "rise_stop": "97.94",
         "fall_stop": "80.14",
         "currency_unit": "CNY",
         "amount": "1.10859035026E9",
         "net_assets": "5.0457",
         "hasexist": "",
         "has_warrant": "0",
         "type": "11",
         "flag": "1",
         "rest_day": "",
         "amplitude": "6.68",
         "lot_size": "100",
         "tick_size": "0.01",
         "kzz_stock_symbol": "",
         "kzz_stock_name": "",
         "kzz_stock_current": "0.0",
         "kzz_convert_price": "0.0",
         "kzz_covert_value": "0.0",
         "kzz_cpr": "0.0",
         "kzz_putback_price": "0.0",
         "kzz_convert_time": "",
         "kzz_redempt_price": "0.0",
         "kzz_straight_price": "0.0",
         "kzz_stock_percent": "",
         "pb": "16.68",
         "benefit_before_tax": "0.0",
         "benefit_after_tax": "0.0",
         "convert_bond_ratio": "",
         "totalissuescale": "",
         "outstandingamt": "",
         "maturitydate": "",
         "remain_year": "",
         "convertrate": "0.0",
         "interestrtmemo": "",
         "release_date": "",
         "circulation": "0.0",
         "par_value": "0.0",
         "due_time": "0.0",
         "value_date": "",
         "due_date": "",
         "publisher": "",
         "redeem_type": "F",
         "issue_type": "",
         "bond_type": "",
         "warrant": "",
         "sale_rrg": "",
         "rate": "",
         "after_hour_vol": "0",
         "float_shares": "192633327",
         "float_market_capital": "1.620816813378E10",
         "disnext_pay_date": "",
         "convert_rate": "0.0",
         "psr": "22.7423"
     }
 }
 */
	
//	@Override
//	public StockDetail parse(String text) {
//        System.out.println("text before:"+text);
//        int i = text.indexOf(":{");
//        text=text.substring(i+1,text.length()-1);
//        System.out.println("text after:"+text);
//        Map<String,String> map = JsonUtils.json2obj(text, Map.class);
//        Set<Map.Entry<String, String>> entries = map.entrySet();
//        for(Map.Entry<String,String> e:entries){
//            String value = e.getValue();
//            if(value.indexOf(".")>-1){
//                System.out.println("public BigDecimal "+e.getKey()+";");
//            }else{
//                System.out.println("public String "+e.getKey()+";");
//            }
//        }
//        return JsonUtils.json2obj(text, StockDetail.class);
//	}

    public StockDetail parse(String text) {
        //System.out.println("text before:"+text);
        int i = text.indexOf(":{");
        text=text.substring(i+1,text.length()-1);
        //System.out.println("text after:"+text);
        Map<String,String> map = JsonUtils.json2obj(text, Map.class);
        return MapUtils.map2obj(map,StockDetail.class);
    }

}
